#include "../queue.h"

#define ERROR -1

#define TEST_SIZE 10
#define TEST_STRING_1 "Kittens"
#define TEST_STRING_2 "Derpy Derp"

int main(int argc, char *argv[])
{
    Queue *queue = NULL;
    int status = 0;
    int i;

    int test_data_length = 1500;
    char test_data[test_data_length];

    printf("\n>>> TESTING CIRCULAR QUEUE <<<\n");

    // TEST #1
    printf("\nTest #1: starting init_queue...\n");
    queue = init_queue(queue, TEST_SIZE);

    printf("\nFirst queue dump...\n");
    dump_queue(queue);

    // TEST #2
    printf("\nTest #2: enqueue...\n");
    status = enqueue(queue, TEST_STRING_1, strlen(TEST_STRING_1));
    if(status == ERROR) printf("ERROR RECEIVED!\n"); 

    printf("\nSecond queue dump...\n");
    dump_queue(queue);

    // TEST #3
    printf("\nTest #3: dequeue...\n");
    status = dequeue(queue, test_data, test_data_length);
    if(status == ERROR) printf("ERROR RECEIVED!\n"); 

    printf("\nThird queue dump...\n");
    dump_queue(queue);

    // TEST #4
    printf("\nTest #4: filling queue...\n");
    for (i = 0; i < TEST_SIZE/2; i++)
    {
        // Add an element to the queue
        status = enqueue(queue, TEST_STRING_1, strlen(TEST_STRING_1));
        if(status == ERROR) printf("ERROR RECEIVED!\n"); 

	// Add another element to the queue
        status = enqueue(queue, TEST_STRING_2, strlen(TEST_STRING_2));
        if(status == ERROR) printf("ERROR RECEIVED!\n"); 

	// Remove an element from the queue
        status = dequeue(queue, test_data, test_data_length);
        if(status == ERROR) printf("ERROR RECEIVED!\n"); 
    }

    printf("\nFourth queue dump...\n");
    dump_queue(queue);

    printf("\nDeleting queue...\n");
    delete_queue(queue);

    // TEST #5
    printf("\nStarting init_queue...\n");
    queue = init_queue(queue, TEST_SIZE);

    printf("\nTest #5: dequeue on empty queue...\n");
    status = dequeue(queue, test_data, test_data_length);
    if(status == ERROR) printf("ERROR RECEIVED!\n"); 

    // TEST #6
    printf("\nTest #6: overflow queue...\n");
    for (i = 0; i < TEST_SIZE + 1; i++)
    {
        // Add an element to the queue
        status = enqueue(queue, TEST_STRING_1, strlen(TEST_STRING_1));
        if(status == ERROR) printf("ERROR RECEIVED!\n"); 
    }

    printf("\nDeleting queue...\n");
    delete_queue(queue);

    printf("\n>>> END TEST <<<\n");

    return 0;
}
